package com.hci.leukemiaapp;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class LeukemiaApp extends TabActivity {
	
	private int startTab;
	
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);

	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab
	    

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    // Initialize a TabSpec for each tab and add it to the TabHost
	    intent = new Intent().setClass(this, WBCActivity.class);
	    spec = tabHost.newTabSpec("wbc").setIndicator("",
                res.getDrawable(R.drawable.ic_tab_wbc))
            .setContent(intent);
	    tabHost.addTab(spec);
	    
	    intent = new Intent().setClass(this, CalendarActivity.class);
	    spec = tabHost.newTabSpec("calendar").setIndicator("",
	                      res.getDrawable(R.drawable.ic_tab_calendar))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, JournalActivity.class);
	    spec = tabHost.newTabSpec("journal").setIndicator("",
	                      res.getDrawable(R.drawable.ic_tab_journal))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, PillBoxActivity.class);
	    spec = tabHost.newTabSpec("pillbox").setIndicator("",
	                      res.getDrawable(R.drawable.ic_tab_pillbox))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    intent = new Intent().setClass(this, PhysiciansActivity.class);
	    spec = tabHost.newTabSpec("physicians").setIndicator("",
                res.getDrawable(R.drawable.ic_tab_physicians))
            .setContent(intent);
	    tabHost.addTab(spec);
	    
	    intent = new Intent().setClass(this, SocialActivity.class);
	    spec = tabHost.newTabSpec("social").setIndicator("",
                res.getDrawable(R.drawable.ic_tab_social))
            .setContent(intent);
	    tabHost.addTab(spec);
	    
	    startTab = savedInstanceState != null ? savedInstanceState.getInt("tab"):0;
	    
	    if(startTab == 0){
            Bundle extras = getIntent().getExtras();
            startTab = extras != null ? extras.getInt("tab") : 1;
        }
	    
	    tabHost.setCurrentTab(startTab-1);
	}
}
